﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Globalization;
using GuildStock.Models;

namespace GuildStock.Services.Blizzard
{
  /// <summary>
  /// Blizzard base service
  /// </summary>
  public partial class BlizzardService : IBlizzardService
  {
    /// <summary>
    /// Blizzard host.
    /// </summary>
     private static readonly string Host = "http://{0}.battle.net";

    /// <summary>
    /// Get REST response for url.
    /// </summary>
    private string GetResponseString(Zones zone, string path)
    {
      string fullUri = this.GetHost(zone) + path;
      
      Uri uri;
      if (!Uri.TryCreate(fullUri, UriKind.Absolute, out uri))
      {
        return null;
      }
      
      var request = WebRequest.Create(uri.ToString());
      var response = request.GetResponse();

      string data = null;
      using (var reader = new StreamReader(response.GetResponseStream()))
      {
        data = reader.ReadToEnd();
      }
      return data;
    }

    /// <summary>
    /// Get blizzard host.
    /// </summary>
    private string GetHost(Zones zone)
    {
      return string.Format(CultureInfo.InvariantCulture, Host, zone.ToString());
    }
  }
}